package com.banksoft.admin.controller;

import com.banksoft.admin.dao.TransferApplyDao;
import com.banksoft.admin.dao.TransferApplyDao;
import com.banksoft.admin.entity.TransferApply;
import com.banksoft.admin.entity.TxApply;
import com.banksoft.admin.service.BaseService;
import com.banksoft.admin.service.TransferApplyService;
import com.banksoft.admin.service.TxApplyService;
import com.banksoft.common.BaseController;
import com.banksoft.common.PageInfo;
import com.banksoft.util.DateUtil;
import com.banksoft.util.StringUtil;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/5/5.
 */
@Controller
@RequestMapping("/transfer")
public class TransferApplyController extends BaseController {
    @Autowired
    BaseService baseService;
    @Autowired
    TransferApplyService transferApplyService;

    @RequestMapping("/list")
    public String list(){
        return "tx/transfer_list";
    }

    @RequestMapping("/listData")
    @ResponseBody
    public Object listData(String status,String startDate,String endDate,PageInfo pageInfo){

        Map<String,Object> map = new HashMap<>();
        map.put("status",status);
        if(StringUtil.isNotNull(startDate))
            map.put("startDate", DateUtil.getLongFormStrDate(startDate));
        if(StringUtil.isNotNull(endDate))
            map.put("endDate",DateUtil.getLongFormStrDate(endDate));

        pageInfo.setParams(map);

        pageInfo = this.page(TransferApplyDao.class,pageInfo);

        return this.getPageResult(pageInfo);
    }


    @RequestMapping("/beforeEdit")
    public String beforeEdit(String id,Model model){
        if(StringUtil.isNotNull(id)){
            TransferApply apply = this.baseService.findById(TransferApplyDao.class,id);
            model.addAttribute("data",apply);
        }
        return "tx/transfer_edit";
    }

    @RequestMapping("/save")
    @ResponseBody
    public Object save(String id,String status,String bz,HttpServletRequest request){
        try {
            JSONObject json = this.transferApplyService.verify(id,status,bz,request);
            return json;
        }catch (Exception e){
            e.printStackTrace();
            return this.FmtResult(false,"审核失败:",null);
        }

    }

}
